<?php
Class Manager_Model_sectionproduct extends Zend_Db_Table
{	
	protected $_name ="section_product";
	protected $_primary ="id";
	
	public function list_category()
	{
		$db = Zend_Registry::get('connectDb');
        $select = $db->select()
		          ->from(array('ue' => 'category'));		          
        $results = $db->fetchAll($select);
        return $results;
	}

	public function listItemabout($status)
	{
	    $db     = Zend_Registry::get('connectDb');
        $select = $db->select()
		             ->from(array('st' => 'section_product'))
		             ->join(array('l' => 'language'),'st.language_id = l.id',array('l.title as ngonngu'))
		             ->where ("st.published=$status or $status=-1")
		             ->order('st.id DESC');		          
        $results = $db->fetchAll($select);
        return $results;
	
	}

	public function searchkq($keyword,$status=-1)
	{
	    $db     = Zend_Registry::get('connectDb');
        $select = $db->select()
		             ->from(array('st' => 'section_product'))
		             ->where("st.published=$status or $status=-1")
		             ->where("st.title like '%$keyword%'");		          
        $results = $db->fetchAll($select);
        return $results;
	}

    public function save($data)
	{	
   
	  $introtext = stripslashes($data['introtext']);
		
	  if ($data['id']=='')
		  {	
			$db    = Zend_Registry::get('connectDb');
	        $data1 = array(
			              	'title'         	=> $data['title'],
	                        'introtext'	        => $introtext,
	                        'published'	        => $data['published'],
							'order'	            => $data['order'],
	                        'language_id'	    => $data['language_id'],
		  				   );
	        $db->insert('section_product', $data1);
		  }
	else 
		  {
			  $tblsection = new Manager_Model_sectionproduct();
			  $where ='id ='.$data['id'];
	    	  $data1 = array(
			              	'title'         	=> $data['title'],
	                        'introtext'	        => $introtext,
	                        'published'	        => $data['published'],
							'order'	            => $data['order'],
	                        'language_id'	    => $data['language_id'],
		  				   );
	    	  $tblsection->update($data1,$where);
		  }  
     }

    public function getrow($id)
	{
				$db = Zend_Registry::get('connectDb');
				$select = $db->select()
		                     ->from(array('st' => 'section_product'))
		                     ->where ("st.id=$id");		                  
      			$result = $db->fetchRow($select);
				return $result;
	}

    public function delete_data($id)
	{
		  	$tblGroup = new Manager_Model_sectionproduct();
			$where = "id =$id";
		    $tblGroup->delete($where);  	
	}

    public function delete_muti($arrParam = null)
	{
	$tblGroup = new Manager_Model_sectionproduct();
		if(count($arrParam['cid'])>0)
	 	{
			$ids = implode(',', $arrParam['cid']);
			$where = 'id IN (' . $ids . ')'; 
			$tblGroup->delete($where); 
			 
	 	}
	}
}